'use strict';

const conn = require('../../libs/Conn');

module.exports = async function (params) {
    if(params.supervision_date === ''){
        params.supervision_date = null
    }
    if(params.inspection_date === ''){
        params.inspection_date = null
    }
    let updateObj = {
        supervision_date:params.supervision_date,
        inspection_result:params.inspection_result,
        inspection_date:params.inspection_date,
        rectification_notice:params.rectification_notice,
        rectification_reply:params.rectification_reply,
        supervision_details:params.supervision_details,
        remarks:params.remarks
    };
    let insertUserSql= ``;
    if(params.user_ids){
        let user_ids=params.user_ids;
        user_ids=user_ids.split(',');
        let deleteSql = `DELETE FROM progress_information_user_middle WHERE information_id = ?`;
        await conn(deleteSql,[params.information_id]);
        for (let user_id in user_ids){
            insertUserSql += `INSERT INTO progress_information_user_middle (information_id, user_id) VALUES ('${params.information_id}', '${user_ids[user_id]}');`;
        }
    }
    let sql = `Update engineering_progress_information_data SET ? WHERE information_id = ?;${insertUserSql}`;
    await conn(sql,[updateObj,params.information_id]);
    return {success: true};

};